package weak_20241227_29.stream;

import java.util.ArrayList;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author zdl
 * @date 2024/12/27
 */
class Person{
    private String name;
    private Integer age;


    public Person() {
    }

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    /**
     * 获取
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     * @return age
     */
    public Integer getAge() {
        return age;
    }

    /**
     * 设置
     * @param age
     */
    public void setAge(Integer age) {
        this.age = age;
    }

    public String toString() {
        return "Person{name = " + name + ", age = " + age + "}";
    }
}
public class Demo19 {
    public static void main(String[] args) {
        //19. 对员工列表按年龄分组，并打印每个年龄组的人数
        ArrayList<Person> list = new ArrayList<>();
        list.add(new Person("张三",22));
        list.add(new Person("李四",23));
        list.add(new Person("无望",24));
        list.add(new Person("赵六",22));
        list.add(new Person("田七",22));
        list.add(new Person("勾八",23));
        list.add(new Person("小九",24));
        Map<Integer, Long> collect = list.stream().collect(Collectors.groupingBy(s -> s.getAge(), Collectors.counting()));
        System.out.println(collect);
    }
}
